package fr.inserm.umr915.vcfserver.bio.ucsc.knownGene;


import java.io.IOException;
import java.util.HashSet;
import java.util.Set;

import com.sleepycat.bind.tuple.TupleBinding;



import fr.inserm.umr915.vcfserver.bio.Segment;
import fr.inserm.umr915.vcfserver.bio.berkeley.DatabaseManager;
import fr.inserm.umr915.vcfserver.util.NameExtractor;
import fr.inserm.umr915.vcfserver.xml.XmlStreamSerializer;


public class KnownGeneHandler extends DatabaseManager<KnownGene>
	{
	private KnownGene.Binding dataBinding=new KnownGene.Binding();
	private KnownGene.StaxSerializer satx=new KnownGene.StaxSerializer();
	private NameExtractor<KnownGene> nameExtractor=new NameExtractor<KnownGene>()
		{
		@Override
		public String getName(KnownGene o)
			{
			return o.getName();
			}
		};
	@Override
	public TupleBinding< KnownGene> getDataBinding()
		{
		return this.dataBinding;
		}
	
	@Override
	public XmlStreamSerializer<KnownGene> getXmlStreamSerializer()
		{
		return satx;
		}
	
	@Override
	public NameExtractor<KnownGene> getNameExtractor() {
		return this.nameExtractor;
		}
	
	@Override
	public KnownGene parse(String line) throws IOException
		{
		KnownGene g= KnownGene.parse(getDelim().split(line));
		if(!acceptChromosome(g.getChrom())) return null;
		return g;
		}
	@Override
	protected Set<String> getNames(KnownGene g)
		{
		Set<String> set=new HashSet<String>();
		set.add(g.getName());
		return set;
		}
	@Override
	public Segment getSegment(KnownGene o) {
		return new Segment(o.getChrom(),o.getTxStart(),o.getTxEnd());
		}
	}
